#{extends 'main.html' /}
<div class="home">
    <div class="page">
        <header class="bar bar-nav">
            <a href="/" class="icon icon-left pull-left"></a>
            <h1 class="title">绑定门禁卡</h1>
        </header>
        <section class="addRepair content scroll_y">
            <div class="list-block">
                <form name="form1" method="post" action="/">
                    <ul>
                        <!-- Text inputs -->

                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <!--<div class="item-title label">业主姓名</div>-->
                                    <div class="item-input">
                                        <input type="text" name="cardNumber" id="cardNumber" value="${code}" placeholder="门禁卡号" readonly>
                                    </div>
                                </div>
                            </div>
                        </li>


                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <!--<div class="item-title label">业主姓名</div>-->
                                    <div class="item-input">
                                        <input type="text" name="name" id="name" value="" placeholder="请输入姓名">
                                    </div>
                                </div>
                            </div>
                        </li>

                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <!--<div class="item-title label">业主姓名</div>-->
                                    <div class="item-input">
                                        <input type="text" name="phone" id="phone" value="" placeholder="请输入电话">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <!--<div class="item-title label">业主姓名</div>-->
                                    <div class="item-input">
                                        <input type="text" name="identityCard" id="identityCard" value="" placeholder="身份证编号">
                                    </div>
                                </div>
                            </div>
                        </li>


                    </ul>
                    <div class="content-block">
                        <input type="button" name="button" class="button sub_btn button-fill button-big button-orange" id="button" value="确认绑定">
                    </div>

                </form>
            </div>

        </section>

        #{include 'weixin/footer.html'/}


    </div>
</div>

<script type="text/javascript">


    $(function() {
        $(document).on('click','.sub_btn', function () {
            $.showPreloader();
            var name = $('#name').val();
            if (name == null || name == '' || name == undefined) {
                $.toast('姓名不能为空');
                return;
            }
            var phone = $('#phone').val();
            if (phone == null || phone == '' || phone == undefined) {
                $.toast('手机号不能为空');
                return;
            }
            var telRe = /^(1)\d{10}$/;
            if (!telRe.test(phone)) {
                $.toast("手机号格式不正确");
                return false;
            }
            var cardNumber = $('#cardNumber').val();
            if (cardNumber == null || cardNumber == '' || cardNumber == undefined) {
                $.toast('卡号不能为空');
                return;
            }
            var identityCard = $('#identityCard').val();
            if (identityCard == null || identityCard == '' || identityCard == undefined) {
                $.toast('身份证号码不能为空');
                return;
            }
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if(reg.test(identityCard) === false){
                $.toast("身份证输入不合法");
                return ;
            }
            $.getJSON("/accesscard/bind",{name : name , phone : phone , cardNumber : cardNumber , identityCard : identityCard},
                    function (data) {
                        $.hidePreloader();
                        if(data.success) {
                            $.router.load("/bankcard/addNewBankCard");
                        } else {
                            $.toast(data.msg);
                        }
                    })
        })

        $.init();
        $(".lunbo").swiper({
            autoplay: 3000  //可选选项，自动滑动
        });

    })
</script>